//
//  YHPictureCollectionView.swift
//  WeiBoYH
//
//  Created by yanhui on 2017/1/9.
//  Copyright © 2017年 yanhui. All rights reserved.
//

import UIKit
private let pictureCellId = "YHPictureCellId"
class YHPictureCollectionView: UICollectionView {

    var pic_urls: [YHPictureInfo]? {
        didSet {
            
            //刷新数据
            self.reloadData()
        }
    }
    //从xib中加载collectionView
    override func awakeFromNib() {

        //注册自定义cell
        register(YHPictureCell.self, forCellWithReuseIdentifier: pictureCellId)
        
        //设置数据源
        self.dataSource = self
    }
    
}

extension YHPictureCollectionView: UICollectionViewDataSource {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return pic_urls?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pictureCellId, for: indexPath) as! YHPictureCell
        //显示图片数据
        cell.pictureInfo = self.pic_urls![indexPath.item]
        return cell
    }
    
}


